<?php
namespace Manage\Controller;

use Think\Controller;

class MapController extends CommonController{
    public function index(){
        $type = '地图管理';
        $m = M('map');
        $mapInfo =  $m->field('id,title,lng,lat')->select();
        $this->assign('map',$mapInfo);
        $this->assign('type',$type);
        $this->display();
    }
    public function add(){
        if (IS_POST) {
            $this->addMap();
            $this->success('添加成功', U('Map/index'));
            exit();
        }
        $this->display();
    }
    public function edit(){
        $id = I('get.id');
        if (IS_POST) {
           $m = M('map');
           $m->create();
           $m->where(['id'=>$id])->save();
           $this->success('修改成功', U('Map/index'));
           exit();
        }
        $m  = M('map')->find($id);
        $this->assign('data',$m);
        $this->display('add');
    }

    private function addMap(){
        $map = M('map');
        if($map->create()){
            $map->add();
        }
    }

    public function del(){
        $id = I('id');
        M('map')->delete($id);
        $this->success('删除成功', U('Map/index'));
        exit();
    }

}
